package com.hammer.m3u8downloader;

import android.app.Application;
import android.content.Context;

import java.io.File;

import jaygoo.library.m3u8downloader.M3U8DownloaderConfig;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        M3U8DownloaderConfig
                .build(getApplicationContext())
                .setSaveDir(getSavePath(getApplicationContext()))
                .setConnTimeout(10000)
                .setReadTimeout(10000)
                .setThreadCount(10)
                .setDebugMode(true);
    }

    private static String getSavePath(Context context) {
        String dataBasePath;
        File dir = context.getExternalFilesDir("");
        if (dir != null) {
            dataBasePath = dir.getAbsolutePath() + "/m3u8";
        } else {
            dataBasePath = context.getFilesDir().getAbsolutePath() + "/m3u8";
        }
        if (!new File(dataBasePath).exists()) {
            new File(dataBasePath).mkdirs();
        }
        return dataBasePath;
    }
}
